﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>添加角色</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../css/Jqbox.css" rel="stylesheet" type="text/css" />
    <link href="../css/jquery.loadmask.css" rel="stylesheet" type="text/css" />
    <script src="../Js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="../Js/ligerui.min.js" type="text/javascript"></script>
    <script src="../Js/jquery.dialog.js" type="text/javascript"></script>
    <script src="../Js/jquery.loadmask.min.js" type="text/javascript"></script>
    <script src="../Js/json2.js" type="text/javascript"></script>
    <script src="../Js/conmon.js" type="text/javascript"></script>
    <script type="text/javascript">
        var Row = null;
        var pWind = null;
        var $grid;
        $(function () {
            $("#areid").val("-1");
            $("#arename").text("");
            //$selectRow
            pWind = parent.window.parent.window.getWindow();
            if (pWind) {
                var temp = parseInt($("#Aid", pWind.document).val());
                var arename = $("#hdAreaName", pWind.document).val()
                $("#areid").val(temp);
                $("#arename").text(arename);

                if (!isNaN(temp)) {
                    $.getJSON('../WebServer/RoleMange.ashx?Action=FenRoleAndRole', { areaid: $("#areid").val(), Rnd: Math.random() }, function (data) {
                        $("#divRole").html("");
                        $.each(data.data, function (i, item) {
                            var str = "<div style='float:left;width:180px;padding:2px;'>";
                            if (i % 3 == 0 && i != 0)
                                str = "<div style='clear:both;float:left;width:180px;padding:2px;'>";
                            if (item.issslect == 1) {
                                str += "<input type='checkbox' class='selected' name='chkRole' checked='checked' disabled='disabled'  id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";
                            } else {
                                str += "<input type='checkbox' class='noselected' name='chkRole'  id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";

                            }
                            str += "</div>";
                            $("#divRole").append(str);
                        });
                    });
                }

                //                if (!isNaN(temp)) {

                //                    $("#txtArea").ligerComboBox({
                //                        width: 140,
                //                        selectBoxWidth: 200,
                //                        selectBoxHeight: 200, valueField: 'id', treeLeafOnly: false, slide: false, initValue: temp,
                //                        tree: { url: '../WebServer/MainAdmin.ashx?Action=AreaTree', checkbox: false },
                //                        onSelected: function (newvalue) {
                //                            //获取职务列表
                //                            if (newvalue > 0) {
                //                                $.getJSON('../WebServer/RoleMange.ashx?Action=FenRoleAndRole', { areaid: newvalue, Rnd: Math.random() }, function (data) {
                //                                    $("#divRole").html("");
                //                                    $.each(data.data, function (i, item) {
                //                                        var str = "<div style='float:left;width:180px;padding:2px;'>";
                //                                        if (i % 3 == 0 && i != 0)
                //                                            str = "<div style='clear:both;float:left;width:180px;padding:2px;'>";
                //                                        if (item.issslect == 1) {
                //                                            str += "<input type='checkbox' class='selected' name='chkRole' checked='checked' disabled='disabled'  id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";
                //                                        } else {
                //                                            str += "<input type='checkbox' class='noselected' name='chkRole'  id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";

                //                                        }
                //                                        str += "</div>";
                //                                        $("#divRole").append(str);
                //                                    });
                //                                });
                //                            } //end if
                //                        } //end onselect
                //                    });


                //保存
                $("#btnSave").click(function () {
                    var areid = $("#areid").val();
                    if (parseInt(areid) != -1) {
                        var selectid = "";
                        $("#divRole input:checked").not(":disabled").each(function () {

                            selectid += $(this).val() + ",";
                        });
                        if (selectid != "") {
                            var pars = { arid: areid, data: selectid };
                            $("body").mask("数据处理中，请稍候......");
                            $.post('../WebServer/RoleMange.ashx?Action=SaveRole', pars, function (data) {
                                $("body").unmask();
                                var rdata = eval("(" + data + ")");
                                if (rdata.IsSuccess > 0) {
                                    showAlertOk("保存成功");
                                    //loadList();
                                    if (pWind) pWind.loadGrid();
                                } else {

                                    showErrorTip(rdata.Msg);
                                }
                            });
                        }

                    } //end chk
                });

            } //end if




            $("#btnCancel").click(function () { closeRefresh(false, ""); });

        });

//        function loadList() {
//            $.getJSON('../WebServer/RoleMange.ashx?Action=FenRoleAndRole', { areaid: $("#txtArea_val").val(), Rnd: Math.random() }, function (data) {
//                $("#divRole").html("");
//                $.each(data.data, function (i, item) {
//                    var str = "<div style='float:left;width:180px;padding:2px;'>";
//                    if (i % 3 == 0 && i != 0)
//                        str = "<div style='clear:both;float:left;width:180px;padding:2px;'>";
//                    if (item.issslect == 1) {
//                        str += "<input type='checkbox' class='selected' name='chkRole' checked='checked' disabled='disabled'  id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";
//                    } else {
//                        str += "<input type='checkbox' class='noselected' name='chkRole'  id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";

//                    }
//                    str += "</div>";
//                    $("#divRole").append(str);
//                });
//            });
//        }

        function chk() {
            var err = "";

            if ($.trim($("#txtArea").val()) == "") {
                err = "请选择区域!";
                showErrorTip(err);
                return false;
            }

            return true;
        }
      
    </script>
    <style type="text/css">
        .edittable td.editcellmessage, .edittable td.editcellverify, .edittable td.editcell
        {
            padding: 5px;
            line-height: 25px;
        }
        .edittable td.editcellmessage
        {
            padding-left: 20px;
        }
        body
        {
            font-size: 12px;
            background: white;
        }
    </style>
</head>
<body>
    <form id="from1" action="">
    <div class="l-panel-search">
        <div class="l-panel-search-item">
            <span>区域：</span>
        </div>
        <div class="l-panel-search-item">
            <span id="arename"></span>
        </div>
    </div>
    <table cellpadding="0" border="0" cellspacing="0" class="edittable">
        <tr>
            <td class="editcellmessage">
                职务:
            </td>
            <td>
                <div id="divRole">
                </div>
            </td>
        </tr>
    </table>
    <div class="buttonpanel">
        <div style="float: right; margin-right: 10px;">
            <a id="btnSave" class="button" href="javascript:void(0);"><span>保存</span></a> <a
                id="btnCancel" class="button" href="javascript:void(0);"><span>关闭</span></a>
        </div>
    </div>
    </form>
    <input type="hidden" id="areid" value ="-1" />
    <input type="hidden" id="arename" value ="" />
</body>
</html>
